import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:wallpaper/components/appbar_base.dart';
import 'package:wallpaper/themes/theme_provider.dart';

class ThemePage extends StatefulWidget {
  const ThemePage({super.key});

  @override
  State<ThemePage> createState() => _ThemePageState();
}

class _ThemePageState extends State<ThemePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppbarBase(title: '主题设置'),
        body: Consumer<ThemeProvider>(builder: (context, provider, child) {
          return Padding(
            padding: const EdgeInsets.all(8.0),
            child: Flex(
              direction: Axis.vertical,
              spacing: 10,
              children: [
                SizedBox(
                  child: Material(
                    borderRadius: BorderRadius.circular(10),
                    clipBehavior: Clip.antiAlias,
                    color: Theme.of(context).colorScheme.primaryContainer,
                    child: InkWell(
                      onTap: () {
                        provider.setLightTheme();
                      },
                      child: Row(
                        children: [
                          Radio(
                              value: !provider.isDarkMode &&
                                  !provider.followSystem,
                              groupValue: true,
                              onChanged: (value) {
                                provider.setLightTheme();
                              }),
                          Text('浅色模式')
                        ],
                      ),
                    ),
                  ),
                ),
                Material(
                  borderRadius: BorderRadius.circular(10),
                  clipBehavior: Clip.antiAlias,
                  color: Theme.of(context).colorScheme.primaryContainer,
                  child: InkWell(
                    onTap: () {
                      provider.setDarkTheme();
                    },
                    child: Row(
                      children: [
                        Radio(
                            value:
                                provider.isDarkMode && !provider.followSystem,
                            groupValue: true,
                            onChanged: (value) {
                              provider.setDarkTheme();
                            }),
                        Text('暗色模式')
                      ],
                    ),
                  ),
                ),
                Material(
                  borderRadius: BorderRadius.circular(10),
                  clipBehavior: Clip.antiAlias,
                  color: Theme.of(context).colorScheme.primaryContainer,
                  child: InkWell(
                    onTap: () {
                      provider.setFollowSystem();
                    },
                    child: Row(
                      children: [
                        Radio(
                            value: provider.followSystem,
                            groupValue: true,
                            onChanged: (value) {
                              provider.setFollowSystem();
                            }),
                        Text('跟随系统')
                      ],
                    ),
                  ),
                ),
              ],
            ),
          );
        }));
  }
}
